//
//  YZDoctorTableView.m
//  kuaiyi
//
//  Created by WGP on 16/5/4.
//
//

#import "YZDoctorTableView.h"
#import "YZDiseaseTypeViewModel.h"
#import "YZDoctorModel.h"
#import "YZDoctorTableViewCell.h"
#import "YZDoctorBaseInfoViewController.h"
#import <MJRefresh.h>

@interface YZDoctorTableView ()

@property(nonatomic,strong)NSArray *doctors;

@end
static NSString *ReuseIdentifier = @"doctors";
@implementation YZDoctorTableView

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择医生";
    
    //    下拉刷新控件
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.tableView.mj_header endRefreshing];
        });
        
    }];
    
    //    上拉刷新控件
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.tableView.mj_footer endRefreshing];
        });
    }];
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"jiantou"] style:UIBarButtonItemStylePlain target:self action:@selector(arrowItemDidClick)];
    
    [YZDiseaseTypeViewModel loadDoctorsfinished:^(NSArray *array, NSError *error) {
        
        self.doctors = array;
        [self.tableView reloadData];
    }];
    
}

-(void)arrowItemDidClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.doctors.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YZDoctorTableViewCell *cell = [YZDoctorTableViewCell doctorCellWith:tableView];
    cell.doctorModel = self.doctors[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YZDoctorModel *doctorModel = self.doctors[indexPath.row];
    
    YZDoctorBaseInfoViewController *doctorVC = [[YZDoctorBaseInfoViewController alloc] init];
    doctorVC.doctorModel = doctorModel;
    [self.navigationController pushViewController:doctorVC animated:YES];
}

@end
